Add compass probe helper functions#31606
Conversation
1fb7159 to
08b9930
Compare
|
Tested on a CubeOrange with an external HMC5883 |
tridge
left a comment
There was a problem hiding this comment.
we need to think about how to validate this PR, tricky!
| return; | ||
| } | ||
| auto *backend = AP_Compass_AK09916::probe_ICM20948( | ||
| GET_I2C_DEVICE(i2c_bus, HAL_COMPASS_AK09916_I2C_ADDR), |
There was a problem hiding this comment.
not using the address arguments
|
|
||
| #endif // #if AP_COMPASS_AK09916_ENABLED && AP_COMPASS_ICM20948_ENABLED | ||
|
|
||
| void Compass::probe_i2c_dev(DriverType driver_type, AP_Compass_Backend* (*probefn)(AP_HAL::OwnPtr<AP_HAL::Device>, bool, Rotation), uint8_t i2c_bus, uint8_t i2c_addr, bool external, Rotation rotation) |
There was a problem hiding this comment.
should typedef a function ptr for this, maybe AP_Compass::probe_i2c_fn_t ?
There was a problem hiding this comment.
Added 3x aliases for that mess.
| add_backend(driver_type, backend); // add_backend does nullptr check | ||
| } | ||
|
|
||
| void Compass::probe_spi_dev(DriverType driver_type, AP_Compass_Backend* (*probefn)(AP_HAL::OwnPtr<AP_HAL::Device>, bool, Rotation), const char *name, bool external, Rotation rotation) |
There was a problem hiding this comment.
maybe AP_Compass::probe_spi_ext_fn_t ?
There was a problem hiding this comment.
how does it make sense to have an external bool on an SPI device?
There was a problem hiding this comment.
Good question! We will find out as more cleanups emerge. Which they will.
.... also, I don't think there's any reason you couldn't have a compass connected externally via SPI...
|
|
||
| // short-lived method which expectes a probe function that doesn't | ||
| // offer the ability to specify an external rotation: | ||
| void Compass::probe_spi_dev(DriverType driver_type, AP_Compass_Backend* (*probefn)(AP_HAL::OwnPtr<AP_HAL::Device>, Rotation), const char *name, Rotation rotation) |
There was a problem hiding this comment.
maybe AP_Compass::probe_spi_fn_t ?
There was a problem hiding this comment.
Added 3x probe aliases
cb926d5 to
4630bed
Compare
There was a problem hiding this comment.
You missed DRIVER_MMC5XX3.
Other than that everything matches up. I printed the PR out on paper and checked with a pen that everything lined up! Would be happy to merge after that one is fixed.
Cleanup ideas (not mandatory):
- fix the comment on LIS3MDL bus number while in there
- there are several
HAL_COMPASS_*_ORIENTATION_INTERNALthat can't be used e.g. QMC5883P asall_externalis guaranteed true - if we use helper methods or adjust the other
add_backendinvocations we can fully prevent leaks and drop the enabled check in it - 90% of these could be packed into a struct and iterated over in one loop. Presumably this is what you were suggesting on the call? Preserving ordering might be tricky.
4630bed to
fdf2e46
Compare
Ah, late entry. Fixed.
Thanks!
Future PR. There are actually a bunch of incorrect comments floating around IIRC.
Yes, and there's the inconsistency with the SPI compasses too which should be addressed!
In Baro I ended up with something like a
Yes, I've done that and it does work quite nicely. I have a branch here somewhere. I've actually tried two different flavours of that, one which uses static const structures and one that doesn't.
|
... and stop leaking memory if the device isn't enabled
fdf2e46 to
4d381a5
Compare




(and adjust backends to take HAL::Device rather than HAL::I2CDevice)
This is primarily to reduce the number of calls to
i2c_mgr->get_deviceandhal.spi->get_deviceso moving away from OwnPtr is easier.However, we also: